package com.ruoyi.car.controller;

import com.ruoyi.car.domain.Passenger;
import com.ruoyi.car.service.IPassengerService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 乘客信息Controller
 * 
 * @author xiaolin
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/system/passenger")
public class PassengerController extends BaseController
{
    @Autowired
    private IPassengerService passengerService;

    /**
     * 查询乘客信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:list')")
    @GetMapping("/list")
    public TableDataInfo list(Passenger passenger)
    {
        startPage();
        List<Passenger> list = passengerService.selectPassengerList(passenger);
        return getDataTable(list);
    }

    /**
     * 导出乘客信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:export')")
    @Log(title = "乘客信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Passenger passenger)
    {
        List<Passenger> list = passengerService.selectPassengerList(passenger);
        ExcelUtil<Passenger> util = new ExcelUtil<Passenger>(Passenger.class);
        util.exportExcel(response, list, "乘客信息数据");
    }

    /**
     * 获取乘客信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(passengerService.selectPassengerById(id));
    }

    /**
     * 新增乘客信息
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:add')")
    @Log(title = "乘客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Passenger passenger)
    {
        return toAjax(passengerService.insertPassenger(passenger));
    }

    /**
     * 修改乘客信息
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:edit')")
    @Log(title = "乘客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Passenger passenger)
    {
        return toAjax(passengerService.updatePassenger(passenger));
    }

    /**
     * 删除乘客信息
     */
    @PreAuthorize("@ss.hasPermi('system:passenger:remove')")
    @Log(title = "乘客信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(passengerService.deletePassengerByIds(ids));
    }

    @Anonymous
    @GetMapping("/wxlogin")
    public AjaxResult wxLogin(@RequestParam("code") String code)
    {
        return AjaxResult.success(passengerService.wxlogin(code));
    }
}
